/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jtwitterclient;

/**
 *
 * @author Administrator
 */
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JButton;

public class ImageButton extends JButton {

    public ImageButton(String img, String str) {
        this(new ImageIcon(img), str);
        //System.out.print(img);
    }

    public ImageButton(ImageIcon icon, String str) {
        setSize(icon.getImage().getWidth(null), icon.getImage().getHeight(null));
        setIcon(icon);
        setMargin(new Insets(0, 0, 0, 0)); //设置按钮边框和标签之间的空白
        setIconTextGap(0);   //设置文本间隙
        setBorderPainted(false); //设置是否允许绘制边框
        setOptions(str);
        setBorder(null);
        setText(null);
    }

    void setOptions(String str) {
        String clicked = "img/" + str + "clicked.PNG";
        String refered = "img/" + str + "refered.PNG";
        setPressedIcon(new ImageIcon(clicked));
        setRolloverIcon(new ImageIcon(refered));
        setSelectedIcon(new ImageIcon(refered));
        setRolloverSelectedIcon(new ImageIcon(refered));
        //setDisabledIcon(new ImageIcon("img/postclicked.PNG"));
        setDisabledSelectedIcon(new ImageIcon(refered));
    }
}
